package Java8实战._1_Lambda._9_Lambda应用;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class _9_1_1_Lambda应用_Predicate {

    public static void main(String[] args) {

        List<String> list = Arrays.asList("qwe","123456","jiangboyang","0");

        List<String> result;

        result = filter(list, (String str) -> str.length() > 3);
        print(result);
    }

    public static <T> List<T> filter(List<T> list, Predicate<T> predicate){

        List<T> result = new ArrayList<>();
        for (T t : list){
            if (predicate.test(t)){
                result.add(t);
            }
        }
        return result;
    }

    public static <T> void print(List<T> list){

        for (T t : list){
            System.out.println(t);
        }
    }
}
